package zuosheng.Binarytree;

/**
 * @author lj
 * @Description: 递归遍历二叉树
 * @date 2020-11-14 19:38
 * @QQ 851477108
 */


public class diguibianli{
    public class Node{
        public int value;
        public Node left;
        public Node right;
        public Node(int data){
            this.value = data;
        }
    }

    //前序遍历
    public void preOrderRecur(Node head){
        if (head == null){
            return;
        }

        System.out.print(head.value + " ");
        preOrderRecur(head.left);
        preOrderRecur(head.right);
    }

    //中序遍历
    public void inOrderRecur(Node head){
        if (head == null){
            return;
        }

        inOrderRecur(head.left);
        System.out.println(head.value + " ");
        inOrderRecur(head.right);
    }

    //后序遍历
    public void posOrderRecur(Node head){
        if (head == null){
            return;
        }

        posOrderRecur(head.left);
        preOrderRecur(head.right);
        System.out.println(head.value + " ");
    }
}
